package filter;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import util.*;

import model.*;

public class MessageFilter implements Filter {

	public void destroy() {


	}

	public void doFilter(ServletRequest request, ServletResponse response,	FilterChain chain) throws IOException, ServletException {

		System.out.println("Message");
		
		HttpServletRequest hrequest = (HttpServletRequest) request;
		HttpSession session = hrequest.getSession();
		
		//User user = (User)hrequest.getAttribute("user");
		
		if(!session.equals(null))
		{
			User user = (User)session.getAttribute("user");
			
			if(user != null)
			{
				//쪽지대응---------------------
				MessageDAO msg = new MessageDAO();
				int msgcnt = msg.getMessageCount(user.getMid(), 0);
				user.setMsg(""+msgcnt);	
				//-----------------------------
				session.setAttribute("user", user);
			}
		}
		
		
		chain.doFilter(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {


	}

}
